{% extends "base.html" %}
{% set title = "学生列表" %}
{% block content %}
    <h2>学生信息</h2>
    <table class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>专业</th>
                <th>选课</th>
                <th>密码</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for student in students %}
            <tr>
                <td>{{ student.id }}</td>
                <td>{{ student.username }}</td>
                <td>{{ student.age }}</td>
                <td>{{ student.gender }}</td>
                <td>{{ student.major.name if student.major else '无专业' }}</td>
                <td>{{ student.course.name if student.course else '无选课' }}</td>
                <td>{{ student.password }}</td>
                <td>
                    {% if is_admin or ( session['role'] == 'student' and student.id == session['uid']) %}
                    <a href="{{ url_for('edit_student', id=student.id) }}" class="btn btn-warning btn-sm">编辑</a> 
                    <a href="{{ url_for('select_course', id=student.id) }}" class="btn btn-success btn-sm">选课</a>
                    <a href="{{ url_for('cancel_course', id=student.id) }}" class="btn btn-secondary btn-sm">退课</a>
                    {% if is_admin %}
                    <a href="{{ url_for('delete_student', id=student.id) }}" class="btn btn-danger btn-sm">删除</a><br>
                    {% endif %}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <br>
    
    {% if is_admin %}
    <a href="{{ url_for('add_student') }}" class="btn btn-primary mb-3">添加学生</a><br>
    {% endif %}
    <a href="{{ url_for('logout') }}" class="btn btn-secondary mb-3">登出</a>

{% endblock %}

